package com.wenx.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

import java.util.Date;

/**
 * camel 通过cxf与webservice通信
 */
public class App6 extends RouteBuilder {

    public static void main(String[] args) throws Exception {

        CamelContext context = new DefaultCamelContext();
        //new ClassPathXmlApplicationContext("jetty/camel.xml");
        context.addRoutes(new App6());
        context.start();
        boolean loop = true;
        while (loop) {
            Thread.sleep(25000);
        }
        context.stop();
    }

    public void configure() throws Exception {
        String content = "hello webservice";
        from("timer:foo?repeatCount=1")
                .setBody(constant(content))             //set request body
                .to("cxf:"
                        + "http://localhost:8080/wx_service/WebService" //service address
                        + "?"
                        + "wsdlURL=http://localhost:8080/wx_service/WebService?wsdl"    //wsdl url
                        + "&"
                        + "dataFormat=RAW"        //dataformat type
                )
                //.convertBodyTo(String.class)
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        System.out.println(exchange.getIn().getBody());
                    }
                })
                .to("log:output");
    }
}
